﻿using System;
using System.Linq;
using System.Windows.Threading;
using System.Windows;
using System.Windows.Input;
using SnakeGame.Models;
using SnakeGame.Views;
using System.Windows.Media;

namespace SnakeGame.ViewModels
{
    class QuestionSelectionViewModel
    {
        public ICommand StartCommand { get; set; }
        public int Win { get; set; }
        public int Lose { get; set; }

        QuestionFrame _frame;

        public QuestionSelectionViewModel()
        {
            StartCommand = new RelayCommand(OnStartCommand);
        }

        internal void Initialize(QuestionFrame questionFrame)
        {
            _frame = questionFrame;
            Win = _frame.QuestionItem.Win;
            Lose = _frame.QuestionItem.Lose;
        }

        private void OnStartCommand(object obj)
        {
            int index = 1;
            var o = obj as string;
			if (o != null)
	            index = int.Parse(o);

            _frame.SelectedQuestion = _frame.QuestionItem.QuestionList.Where(x => x.ID == index).FirstOrDefault();

            QuestionPage qPage = new QuestionPage();
            qPage.Initialize(_frame);
            _frame.Navigate(qPage);
        }

    }
}
